<template>
  <div style="display: flex;line-height: 60px">
    <div style="margin-top: 8px;">
      <i :class="icon" style="font-size: 20px;cursor: pointer;" @click="collapse"></i>
    </div>
    <div style="flex: 1;text-align: center;font-size: 34px;">
      <span>欢迎来到仓库管理系统</span>
    </div>
    <el-dropdown>
      <span>{{user.name}}</span>
      <i class="el-icon-arrow-down" style="margin-left: 5px"></i>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
        <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      user: "",
    };
  },
  methods: {
    toUser(){
      this.$router.push('/info')
    },
    logout(){
      this.$store.commit('logout')
      localStorage.clear()
      this.$router.push('/')
    },
    collapse() {
      // 发送是否折叠的信号，让父组件处理折叠
      this.$emit('doCollapse')
    },
  },
  props:{
    icon:String
  },
  created() {
    this.user = this.$store.getters.getUser
  }
}
</script>

<style scoped>

</style>
